/*******************************************************************************
 * Package: com.hngtrust.iir.user.service.impl
 * Type:    GenerateReportServiceImpl
 * Date:    2021/6/4 20:29
 *
 * Copyright (c) 2021 HUANENG GUICHENG TRUST CORP.,LTD All Rights Reserved.
 *
 * You may not use this file except in compliance with the License.
 *******************************************************************************/
package com.hngtrust.iir.user.service.impl;

import cn.afterturn.easypoi.word.WordExportUtil;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.hngtrust.framework.security.util.SecurityUtils;
import com.hngtrust.iir.company.controller.vo.ListAssetDebtRespVO;
import com.hngtrust.iir.company.controller.vo.ListAssetStructRespVO;
import com.hngtrust.iir.company.controller.vo.ListBankCreditRespVO;
import com.hngtrust.iir.company.controller.vo.ListBidRespVO;
import com.hngtrust.iir.company.controller.vo.ListBondFinanceRespVO;
import com.hngtrust.iir.company.controller.vo.ListCashFlowRespVO;
import com.hngtrust.iir.company.controller.vo.ListCashStructRespVO;
import com.hngtrust.iir.company.controller.vo.ListChangeRespVO;
import com.hngtrust.iir.company.controller.vo.ListCompDpAnalyDataRespVO;
import com.hngtrust.iir.company.controller.vo.ListCompDpAnalysRespVO;
import com.hngtrust.iir.company.controller.vo.ListComprehensiveRespVO;
import com.hngtrust.iir.company.controller.vo.ListContrastRespVO;
import com.hngtrust.iir.company.controller.vo.ListCreditRateRespVO;
import com.hngtrust.iir.company.controller.vo.ListDebitCreditRespVO;
import com.hngtrust.iir.company.controller.vo.ListFinanceGradeAvgRespVO;
import com.hngtrust.iir.company.controller.vo.ListFinanceGradeEvaluateRespVO;
import com.hngtrust.iir.company.controller.vo.ListFinanceGradeRespVO;
import com.hngtrust.iir.company.controller.vo.ListFinanceGradeValueRespVO;
import com.hngtrust.iir.company.controller.vo.ListGuaranteeRespVO;
import com.hngtrust.iir.company.controller.vo.ListHolderRespVO;
import com.hngtrust.iir.company.controller.vo.ListInvestRespVO;
import com.hngtrust.iir.company.controller.vo.ListManagementRespVO;
import com.hngtrust.iir.company.controller.vo.ListOperationRespVO;
import com.hngtrust.iir.company.controller.vo.ListProfitRespVO;
import com.hngtrust.iir.company.controller.vo.ListProfitStructRespVO;
import com.hngtrust.iir.company.controller.vo.ListQualificationRespVO;
import com.hngtrust.iir.company.controller.vo.ListTaxRespVO;
import com.hngtrust.iir.company.controller.vo.ViewCompanyRespVO;
import com.hngtrust.iir.company.dto.ListSubsidiaryDTO;
import com.hngtrust.iir.myreport.entity.SelfReport;
import com.hngtrust.iir.myreport.service.SelfReportService;
import com.hngtrust.iir.report.controller.dto.ABalanceStructVO;
import com.hngtrust.iir.report.controller.dto.ACashStructVO;
import com.hngtrust.iir.report.controller.dto.AProfitStructVO;
import com.hngtrust.iir.report.controller.dto.SynthAnalysVO;
import com.hngtrust.iir.risk.controller.dto.QueryCompRiskTypeRespVO;
import com.hngtrust.iir.risk.controller.dto.RedRiskType;
import com.hngtrust.iir.risk.controller.dto.YellowRiskType;
import com.hngtrust.iir.risk.dto.QueryCompAssociateDTO;
import com.hngtrust.iir.user.controller.dto.BriefingVO;
import com.hngtrust.iir.user.controller.dto.BusinessArea;
import com.hngtrust.iir.user.controller.dto.BusinessIndustry;
import com.hngtrust.iir.user.controller.dto.BusinessProduct;
import com.hngtrust.iir.user.controller.dto.BusinessVO;
import com.hngtrust.iir.user.controller.dto.ListFinanceCostsRespVO;
import com.hngtrust.iir.user.controller.dto.ListOneselfRiskRespVO;
import com.hngtrust.iir.user.controller.dto.MainBusiness;
import com.hngtrust.iir.user.controller.dto.MainBusinessVO;
import com.hngtrust.iir.user.controller.dto.ManageInfoVO;
import com.hngtrust.iir.user.controller.dto.OnUnderVO;
import com.hngtrust.iir.user.controller.dto.TitleVO;
import com.hngtrust.iir.user.controller.dto.ViewStockRightRespVo;
import com.hngtrust.iir.user.entity.User;
import com.hngtrust.iir.user.service.GenerateReportService;
import com.hngtrust.iir.util.DateUtils;
import com.hngtrust.iir.util.WordExportUtils;
import com.tiger.web.service.FileService;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ooxml.POIXMLDocumentPart;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.xwpf.usermodel.XWPFChart;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTAxDataSource;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTBarChart;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTBarSer;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTChart;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTLineChart;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTLineSer;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumData;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumDataSource;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumVal;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTPieChart;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTPieSer;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTPlotArea;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTStrData;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTStrVal;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 生成研报service
 *
 * @author Keqiwei
 * @date 2021/6/4 20:29
 */
@Service
@Slf4j
public class GenerateReportServiceImpl implements GenerateReportService {
    
    
    
    @Autowired
    @Qualifier("minIoFileService")
    private FileService fileService;
    
    @Value("${word.template}")
    private String wordTemplate;
    
    @Value("${create.report.minio}")
    private String create;
    
    @Autowired
    private SelfReportService selfReportService;
    
    private static ObjectMapper objectMapper = new ObjectMapper();
    
    private static final String DIRECTORY = System.getProperty("java.io.tmpdir");
    
    @Override
    public String upload(SelfReport req,String path) throws Exception {
    
        objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        Map<String,Object> map = new HashMap<>();
        
        
        req.setUpdateTime(new Date());//修改时间
        User loginUser = (User) SecurityUtils.getLoginUser().getAdditionalInfo();
        req.setUpdateUserId(loginUser.getId());//修改人
        BigDecimal bigDecimal = new BigDecimal(10000);
      
        TitleVO module = objectMapper.readValue(req.getModule(), TitleVO.class); //模块树
    
        BusinessVO businessVO = new BusinessVO();
        map.put("businesVO",businessVO);
        if (req.getBusinessInfo() != null && !req.getBusinessInfo().isEmpty()){
             businessVO = objectMapper.readValue(req.getBusinessInfo(), BusinessVO.class);//工商信息
            String format = DateUtils.format(businessVO.getFoundDate(), DateUtils.DATE);
            businessVO.setFound(format);
            businessVO.setEnd(DateUtils.format(businessVO.getEndDate(),DateUtils.DATE));
            
            if (businessVO.getListed() != null){
                if (businessVO.getListed() == 0){
                    businessVO.setListeds("否");
                }
                if (businessVO.getListed() == 1){
                    businessVO.setListeds("是");
                }
            }
            if (businessVO.getVie() != null){
                if (businessVO.getVie() == 0){
                    businessVO.setV("否");
                }
                if (businessVO.getVie() == 1){
                    businessVO.setV("是");
                }
            }
            if (null != businessVO.getManageLimit()){
                businessVO.setManage(businessVO.getManageLimit());
            }
            map.put("businesVO",businessVO);
        }
    
        BriefingVO briefingVO = new BriefingVO();
        map.put("briefing",briefingVO);
        if (req.getCompNote() != null && !req.getCompNote().isEmpty()){
            briefingVO = objectMapper.readValue(req.getCompNote(), BriefingVO.class);//公司简介
            map.put("briefing",briefingVO);
        }
        log.error("股权结构"+req.getStockStruct());
        List<ListHolderRespVO> stockStruct = objectMapper.readValue(req.getStockStruct(),
                objectMapper.getTypeFactory().constructParametricType(List.class, ListHolderRespVO.class));//股权结构
        map.put("stockStruct",stockStruct);
            
        List<ListManagementRespVO> management  = objectMapper.readValue(req.getCompManage(),
                objectMapper.getTypeFactory().constructParametricType(List.class, ListManagementRespVO .class));//公司治理
        management.forEach(m->{
            m.setStart(DateUtils.format(m.getStartDate(),DateUtils.DATE));
            m.setLeave(DateUtils.format(m.getLeaveDate(),DateUtils.DATE));
        });
        map.put("management",management);
            
        List<ListChangeRespVO> change = objectMapper.readValue(req.getEvolution(),
                objectMapper.getTypeFactory().constructParametricType(List.class, ListChangeRespVO.class));//历史沿革
        change.forEach(c->{
            c.setTime(DateUtils.format(c.getChangeDate(),DateUtils.DATE));
        });
        map.put("change",change);
            
        List<ListQualificationRespVO> qualification  = objectMapper.readValue(req.getCompQualification(),
                objectMapper.getTypeFactory().constructParametricType(List.class, ListQualificationRespVO.class));//公司资质
        qualification.forEach(q->{
            q.setTime(DateUtils.format(q.getAcquisitionDate(),DateUtils.DATE));
        });
        map.put("qualification",qualification);
    
        
        ManageInfoVO manageInfo = new ManageInfoVO();
        map.put("comstock",manageInfo.getCompStockRespVO());
        map.put("listOperationRespVOS",manageInfo.getListOperationRespVOS());
        if (req.getManageInfo() != null && !req.getManageInfo().isEmpty()){
            manageInfo = objectMapper.readValue(req.getManageInfo(), ManageInfoVO.class);//经营情况
            if(manageInfo.getCompStockRespVO() != null){
                manageInfo.getCompStockRespVO().setTime(DateUtils.format(manageInfo.getCompStockRespVO().getUpdateTime(),DateUtils.DATE));
            }
            map.put("comstock",manageInfo.getCompStockRespVO());
            
            manageInfo.getListOperationRespVOS().forEach(a->{
                if(null != a.getOperRev()){
                    BigDecimal divide = a.getOperRev().divide(bigDecimal);
                    a.setOperRev(divide);
                }
                if(null != a.getNetProfitInclMinIntInc()){
                    BigDecimal divide1 = a.getNetProfitInclMinIntInc().divide(bigDecimal);
                    a.setNetProfitInclMinIntInc(divide1);
                }
                
                
                if(null != a.getTotAssets()){
                    BigDecimal divide2 = a.getTotAssets().divide(bigDecimal);
                    a.setTotAssets(divide2);
                }
                
                if ( null != a.getTotNonCurAssets()) {
                    BigDecimal divide3 = a.getTotNonCurAssets().divide(bigDecimal);
                    a.setTotNonCurAssets(divide3);
                }
                
                
            });
            map.put("listOperationRespVOS",manageInfo.getListOperationRespVOS());
        }
    
    
        MainBusinessVO mainBusiness  = new MainBusinessVO();
        map.put("mainBusiness",mainBusiness.getMainBusinesses());
        map.put("area",mainBusiness.getArea());
        map.put("industry",mainBusiness.getIndustry());
        map.put("product",mainBusiness.getProduct());
        if (req.getMainBusiness() != null && !req.getMainBusiness().isEmpty()){
            mainBusiness  = objectMapper.readValue(req.getMainBusiness(),MainBusinessVO.class);//主营业务
            
            List<MainBusiness> mainBusinesses = mainBusiness.getMainBusinesses();
            
            mainBusinesses.forEach(m->{
                if(null!=m.getReportPeriod()){
                    Date date = new Date(Long.parseLong(m.getReportPeriod()));
                    m.setTime(DateUtils.format(date,DateUtils.DATE));
                }
                if(null != m.getSegmentSales()){
                    BigDecimal divide = m.getSegmentSales().divide(bigDecimal);
                    m.setSegmentSales(divide);
                }
                
            });
            
            map.put("mainBusiness",mainBusinesses);
            List<BusinessArea> area = mainBusiness.getArea();
            area.forEach(a->{
                if (null != a.getSegmentSales()){
                    BigDecimal divide = a.getSegmentSales().divide(bigDecimal);
                    a.setSegmentSales(divide);
                }
                
            });
            map.put("area",area);
            List<BusinessIndustry> industry = mainBusiness.getIndustry();
            industry.forEach(a->{
                if (null != a.getSegmentSales()){
                    BigDecimal divide = a.getSegmentSales().divide(bigDecimal);
                    a.setSegmentSales(divide);
                }
                
            });
            map.put("industry",industry);
            List<BusinessProduct> product = mainBusiness.getProduct();
            product.forEach(a->{
                if (null !=a.getSegmentSales()){
                    BigDecimal divide = a.getSegmentSales().divide(bigDecimal);
                    a.setSegmentSales(divide);
                }
               
            });
            map.put("product",product);
        }
    
    
        OnUnderVO onUnderVO = new OnUnderVO();//上下游关系
        map.put("on",onUnderVO.getOn());
        map.put("Under",onUnderVO.getUnder());
        if (req.getUpdownStream() != null && !req.getUpdownStream().isEmpty()){
            SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
            onUnderVO = objectMapper.readValue(req.getUpdownStream(),OnUnderVO.class);//上下游关系
            onUnderVO.getOn().forEach(o->{
                try {
                    Date parse = format.parse(o.getReportPeriod());
                    o.setReportPeriod(DateUtils.format(parse,DateUtils.DATE));
                    o.setAmount(o.getAmount().divide(new BigDecimal("10000")).setScale(2,BigDecimal.ROUND_HALF_UP));
                } catch (ParseException e) {
                    e.printStackTrace();
                }
            });
            onUnderVO.getUnder().forEach(u->{
                try {
                    Date parse = format.parse(u.getReportPeriod());
                    u.setReportPeriod(DateUtils.format(parse,DateUtils.DATE));
                    u.setAmount(u.getAmount().divide(new BigDecimal("10000")).setScale(2,BigDecimal.ROUND_HALF_UP));
                } catch (ParseException e) {
                    e.printStackTrace();
                }
            });
            map.put("on",onUnderVO.getOn());
            map.put("Under",onUnderVO.getUnder());
        }
        
        List<ListBidRespVO> listBidRespVOS =   objectMapper.readValue(req.getBidTender(),
                    objectMapper.getTypeFactory().constructParametricType(List.class, ListBidRespVO.class));//招投标
        listBidRespVOS.forEach(l->{
            l.setTime(DateUtils.format(l.getReleaseDate(),DateUtils.DATE));
        });
        map.put("listBidRespVOS",listBidRespVOS);
    
    
        ABalanceStructVO aBalanceStructVO = new ABalanceStructVO();
        ListAssetDebtRespVO dataOne = new ListAssetDebtRespVO();
        ListAssetDebtRespVO dataTwo = new ListAssetDebtRespVO();
        ListAssetDebtRespVO dataThree = new ListAssetDebtRespVO();
        ListAssetDebtRespVO dataFour = new ListAssetDebtRespVO();
        ListAssetDebtRespVO dataFive = new ListAssetDebtRespVO();
        map.put("dataFive",dataOne);
        map.put("dataFour",dataTwo);
        map.put("dataThree",dataThree);
        map.put("dataTwo",dataFour);
        map.put("dataOne",dataFive);
        map.put("dataStruct", aBalanceStructVO.getListAssetStructRespVOS());
    
        if (req.getABalanceStruct() != null && !req.getABalanceStruct().isEmpty()){
            aBalanceStructVO = objectMapper.readValue(req.getABalanceStruct(),ABalanceStructVO.class);//资产负债表结构分析
            aBalanceStructVO.getListAssetDebtRespVOS().forEach(l->{
                l.setTime(DateUtils.format(l.getReportPeriod(),"yyyy"));
            });
            for (int i = 0; i < aBalanceStructVO.getListAssetDebtRespVOS().size(); i++) {
                if (i==0){
                    BeanUtils.copyProperties(aBalanceStructVO.getListAssetDebtRespVOS().get(i),dataOne);
                    if (dataOne.getDiv()==1){
                        dataOne.setDivName("元");
                    }
                    if (dataOne.getDiv()==10000){
                        dataOne.setDivName("万");
                    }
                    if (dataOne.getDiv()==1000000){
                        dataOne.setDivName("百万");
                    }
                    if (dataOne.getDiv()==100000000){
                        dataOne.setDivName("亿");
                    }
                    dataOne.setTime(DateUtils.format(dataOne.getReportPeriod(),"yyyy"));
                }
                if (i==1){
                    BeanUtils.copyProperties(aBalanceStructVO.getListAssetDebtRespVOS().get(i),dataTwo);
                    dataTwo.setTime(DateUtils.format(dataTwo.getReportPeriod(),"yyyy"));
                }
                if (i==2){
                    BeanUtils.copyProperties(aBalanceStructVO.getListAssetDebtRespVOS().get(i),dataThree);
                    dataThree.setTime(DateUtils.format(dataThree.getReportPeriod(),"yyyy"));
                }
                if (i==3){
                    BeanUtils.copyProperties(aBalanceStructVO.getListAssetDebtRespVOS().get(i),dataFour);
                    dataFour.setTime(DateUtils.format(dataFour.getReportPeriod(),"yyyy"));
                }
                if (i==4){
                    BeanUtils.copyProperties(aBalanceStructVO.getListAssetDebtRespVOS().get(i),dataFive);
                    dataFive.setTime(DateUtils.format(dataFive.getReportPeriod(),"yyyy"));
                }
            }
            map.put("dataOne",dataOne);
            map.put("dataTwo",dataTwo);
            map.put("dataThree",dataThree);
            map.put("dataFour",dataFour);
            map.put("dataFive",dataFive);
            map.put("dataStruct", aBalanceStructVO.getListAssetStructRespVOS());
           
        }
    
    
        AProfitStructVO aProfitStructVO = new AProfitStructVO();
        ListProfitRespVO data10 = new ListProfitRespVO();
        ListProfitRespVO data9 = new ListProfitRespVO();
        ListProfitRespVO data8 = new ListProfitRespVO();
        ListProfitRespVO data7 = new ListProfitRespVO();
        ListProfitRespVO data6 = new ListProfitRespVO();
        map.put("data6",data10);
        map.put("data7",data9);
        map.put("data8",data8);
        map.put("data9",data7);
        map.put("data10",data6);
        map.put("profitStruct",aProfitStructVO.getListProfitStructRespVOS());
        if (req.getAProfitStruct()!=null && !req.getAProfitStruct().isEmpty()){
            aProfitStructVO = objectMapper.readValue(req.getAProfitStruct(), AProfitStructVO.class);//利润表
            aProfitStructVO.getListProfitRespVOS().forEach(l->{
                l.setTime(DateUtils.format(l.getReportPeriod(),"yyyy"));
            });
            
            
            
            for(int i = 0; i < aProfitStructVO.getListProfitRespVOS().size(); i++){
                if(i == 0){
                    BeanUtils.copyProperties(aProfitStructVO.getListProfitRespVOS().get(i),data10);
                }else if(i == 1){
                    BeanUtils.copyProperties(aProfitStructVO.getListProfitRespVOS().get(i),data9);
                }else if(i == 2){
                    BeanUtils.copyProperties(aProfitStructVO.getListProfitRespVOS().get(i),data8);
                }else if(i == 3){
                    BeanUtils.copyProperties(aProfitStructVO.getListProfitRespVOS().get(i),data7);
                }else if(i == 4){
                    BeanUtils.copyProperties(aProfitStructVO.getListProfitRespVOS().get(i),data6);
                }
            }
            map.put("data6",data10);
            map.put("data7",data9);
            map.put("data8",data8);
            map.put("data9",data7);
            map.put("data10",data6);
            map.put("profitStruct",aProfitStructVO.getListProfitStructRespVOS());
        }
    
    
        ACashStructVO aCashStructVO = new ACashStructVO();
        ListCashFlowRespVO data15  = new ListCashFlowRespVO();
        ListCashFlowRespVO data14  = new ListCashFlowRespVO();
        ListCashFlowRespVO data13  = new ListCashFlowRespVO();
        ListCashFlowRespVO data12  = new ListCashFlowRespVO();
        ListCashFlowRespVO data11  = new ListCashFlowRespVO();
        map.put("data15",data11);
        map.put("data14",data12);
        map.put("data13",data13);
        map.put("data12",data14);
        map.put("data11",data15);
        map.put("cashStruct",aCashStructVO.getListCashStructRespVOS());
        if(req.getACashStruct() != null && !req.getACashStruct().isEmpty()){
            aCashStructVO = objectMapper.readValue(req.getACashStruct(), ACashStructVO.class);//现金流量表
            aCashStructVO.getListCashFlowRespVOS().forEach(l->{
                l.setTime(DateUtils.format(l.getReportPeriod(),"yyyy"));
            });
    
            for(int i = 0; i < aCashStructVO.getListCashFlowRespVOS().size(); i++){
                if(i == 0){
                    BeanUtils.copyProperties(aCashStructVO.getListCashFlowRespVOS().get(i),data15);
                }else if(i == 1){
                    BeanUtils.copyProperties(aCashStructVO.getListCashFlowRespVOS().get(i),data14);
                }else if(i == 2){
                    BeanUtils.copyProperties(aCashStructVO.getListCashFlowRespVOS().get(i),data13);
                }else if(i == 3){
                    BeanUtils.copyProperties(aCashStructVO.getListCashFlowRespVOS().get(i),data12);
                }else if(i == 4){
                    BeanUtils.copyProperties(aCashStructVO.getListCashFlowRespVOS().get(i),data11);
                }
            }
    
            map.put("data15",data11);
            map.put("data14",data12);
            map.put("data13",data13);
            map.put("data12",data14);
            map.put("data11",data15);
            map.put("cashStruct",aCashStructVO.getListCashStructRespVOS());
        }
        
    
        SynthAnalysVO synthAnalysVO = new SynthAnalysVO();
        map.put("listFinanceGradeValueRespVO",new ListFinanceGradeValueRespVO());
        map.put("listFinanceGradeAvgRespVO",new ListFinanceGradeAvgRespVO());
        map.put("synthAnalysVo",synthAnalysVO);
        map.put("listFinanceGradeEvaluateRespVO",new ListFinanceGradeEvaluateRespVO());
        map.put("listComprehensiveRespVO",new ListComprehensiveRespVO());
        if (req.getSynthAnalys() != null && !req.getSynthAnalys().isEmpty()){
            synthAnalysVO=objectMapper.readValue(req.getSynthAnalys(),SynthAnalysVO.class);//综合分析
    
            // 综合分析 -- 财务综合分析
            if(synthAnalysVO.getListComprehensiveRespVO().get(0) != null){
                ListComprehensiveRespVO  listComprehensiveRespVO = synthAnalysVO.getListComprehensiveRespVO().get(0);
                
                map.put("listComprehensiveRespVO",listComprehensiveRespVO);
            }
            
            if (!synthAnalysVO.getListFinanceGradeRespVO().isEmpty()){
                ListFinanceGradeRespVO listFinanceGradeRespVO = synthAnalysVO.getListFinanceGradeRespVO().get(0);
               if (null != listFinanceGradeRespVO.getProfitAbilityConclusion())
                listFinanceGradeRespVO.setP(listFinanceGradeRespVO.getProfitAbilityConclusion().replaceAll("<br />","\n").replaceAll("●","").trim());
               if(null !=listFinanceGradeRespVO.getSolvencyConclusion() )
                listFinanceGradeRespVO.setS(listFinanceGradeRespVO.getSolvencyConclusion().replaceAll("<br />","\n").replaceAll("●","").trim());
               if(null != listFinanceGradeRespVO.getOperationAbilityConclusion())
                listFinanceGradeRespVO.setO(listFinanceGradeRespVO.getOperationAbilityConclusion().replaceAll("<br />","\n").replaceAll("●","").trim());
               if (null !=listFinanceGradeRespVO.getGrowAbilityConclusion())
                listFinanceGradeRespVO.setG(listFinanceGradeRespVO.getGrowAbilityConclusion().replaceAll("<br />","\n").replaceAll("●","").trim());
               if (null != listFinanceGradeRespVO.getCashConclusion() )
                listFinanceGradeRespVO.setC(listFinanceGradeRespVO.getCashConclusion().replaceAll("<br />","\n").replaceAll("●","").trim());
                map.put("listvo",listFinanceGradeRespVO);
            }
            
            // 综合分析 -- 评分详情 -- 财务综合评分详情指标值
            if(synthAnalysVO.getListFinanceGradeRespVO() != null && !synthAnalysVO.getListFinanceGradeRespVO().isEmpty()){
                if (synthAnalysVO.getListFinanceGradeRespVO().get(0)
                        .getListFinanceGradeValueRespVO() != null){
                    ListFinanceGradeValueRespVO listFinanceGradeValueRespVO = synthAnalysVO.getListFinanceGradeRespVO().get(0)
                            .getListFinanceGradeValueRespVO().get(0);
                    map.put("listFinanceGradeValueRespVO",listFinanceGradeValueRespVO);
                }
            }
            
            
    
            // 综合分析 -- 评分详情 -- 财务综合评分详情行业平均值
            if(synthAnalysVO.getListFinanceGradeRespVO() != null && !synthAnalysVO.getListFinanceGradeRespVO().isEmpty()){
                if (synthAnalysVO.getListFinanceGradeRespVO().get(0)
                        .getListFinanceGradeAvgRespVO() != null){
                    ListFinanceGradeAvgRespVO listFinanceGradeAvgRespVO = synthAnalysVO.getListFinanceGradeRespVO().get(0)
                            .getListFinanceGradeAvgRespVO().get(0);
                    map.put("listFinanceGradeAvgRespVO",listFinanceGradeAvgRespVO);
                }
            }
            
            
            // 综合分析 -- 评分详情 -- 财务综合评分详情指标评价
            if(synthAnalysVO.getListFinanceGradeRespVO() != null && !synthAnalysVO.getListFinanceGradeRespVO().isEmpty()){
                if (synthAnalysVO.getListFinanceGradeRespVO().get(0)
                        .getListFinanceGradeEvaluateRespVO() != null){
                    ListFinanceGradeEvaluateRespVO listFinanceGradeEvaluateRespVO = synthAnalysVO.getListFinanceGradeRespVO().get(0)
                            .getListFinanceGradeEvaluateRespVO().get(0);
                    map.put("listFinanceGradeEvaluateRespVO",listFinanceGradeEvaluateRespVO);
                }
            }
            
            
            map.put("synthAnalysVo",synthAnalysVO);
            
        }
        
    
        List<ListCompDpAnalysRespVO> listVO = objectMapper.readValue(req.getADupont(),
                objectMapper.getTypeFactory().constructParametricType(List.class, ListCompDpAnalysRespVO.class));//杜邦分析
        ListCompDpAnalyDataRespVO compDpAnalyDataRespVO1 = new ListCompDpAnalyDataRespVO();
        ListCompDpAnalyDataRespVO compDpAnalyDataRespVO2 = new ListCompDpAnalyDataRespVO();
        ListCompDpAnalyDataRespVO compDpAnalyDataRespVO3 = new ListCompDpAnalyDataRespVO();
        ListCompDpAnalyDataRespVO compDpAnalyDataRespVO4 = new ListCompDpAnalyDataRespVO();
        ListCompDpAnalyDataRespVO compDpAnalyDataRespVO5 = new ListCompDpAnalyDataRespVO();
        List<ListCompDpAnalyDataRespVO> listCompDpAnalyDataRespVO = listVO.get(0).getListCompDpAnalyDataRespVO();
        for (int i = 0; i < listCompDpAnalyDataRespVO.size(); i++) {
            if(null != listCompDpAnalyDataRespVO.get(i).getDriverConclusion()){
                listCompDpAnalyDataRespVO.get(i).setDriverConclusion(listVO.get(0).getListCompDpAnalyDataRespVO().get(i).getDriverConclusion().replaceAll("<br/>",""));
            }
            if(i==0){
                BeanUtils.copyProperties(listCompDpAnalyDataRespVO.get(i),compDpAnalyDataRespVO1);
                
            }else if (i==1){
                BeanUtils.copyProperties(listCompDpAnalyDataRespVO.get(i),compDpAnalyDataRespVO2);
            }else if (i==2){
                BeanUtils.copyProperties(listCompDpAnalyDataRespVO.get(i),compDpAnalyDataRespVO3);
            }else if (i==3){
                BeanUtils.copyProperties(listCompDpAnalyDataRespVO.get(i),compDpAnalyDataRespVO4);
            }else if (i==4){
                BeanUtils.copyProperties(listCompDpAnalyDataRespVO.get(i),compDpAnalyDataRespVO5);
            }
        }
        map.put("compDpAnalyDataRespVO1",compDpAnalyDataRespVO1);
        map.put("compDpAnalyDataRespVO2",compDpAnalyDataRespVO2);
        map.put("compDpAnalyDataRespVO3",compDpAnalyDataRespVO3);
        map.put("compDpAnalyDataRespVO4",compDpAnalyDataRespVO4);
        map.put("compDpAnalyDataRespVO5",compDpAnalyDataRespVO5);
        if("{}".equals(req.getMainIndex())){
            req.setMainIndex("[]");
        }
        List<ListContrastRespVO> listContrastRespVOS = objectMapper.readValue(req.getMainIndex(),
                objectMapper.getTypeFactory().constructParametricType(List.class, ListContrastRespVO.class));//主要指标
        ListContrastRespVO listContrastRespVO1 = new ListContrastRespVO();
        ListContrastRespVO listContrastRespVO2 = new ListContrastRespVO();
        ListContrastRespVO listContrastRespVO3 = new ListContrastRespVO();
        ListContrastRespVO listContrastRespVO4 = new ListContrastRespVO();
        ListContrastRespVO listContrastRespVO5 = new ListContrastRespVO();
        for(int i =0; i < listContrastRespVOS.size(); i++){
            if(i == 0){
                BeanUtils.copyProperties(listContrastRespVOS.get(i),listContrastRespVO1);
            }else if(i == 1){
                BeanUtils.copyProperties(listContrastRespVOS.get(i),listContrastRespVO2);
            }else if(i == 2){
                BeanUtils.copyProperties(listContrastRespVOS.get(i),listContrastRespVO3);
            }else if(i == 3){
                BeanUtils.copyProperties(listContrastRespVOS.get(i),listContrastRespVO4);
            }else if(i == 4){
                BeanUtils.copyProperties(listContrastRespVOS.get(i),listContrastRespVO5);
            }
        }
        map.put("listContrastRespVO1",listContrastRespVO1);
        map.put("listContrastRespVO2",listContrastRespVO2);
        map.put("listContrastRespVO3",listContrastRespVO3);
        map.put("listContrastRespVO4",listContrastRespVO4);
        map.put("listContrastRespVO5",listContrastRespVO5);
    
    
        ViewCompanyRespVO viewCompanyRespVO = new ViewCompanyRespVO();
            map.put("viewCompanyRespVo",viewCompanyRespVO);
            if (req.getStockBaseInfo() != null && !req.getStockBaseInfo().isEmpty()){
                viewCompanyRespVO = objectMapper.readValue(req.getStockBaseInfo(),ViewCompanyRespVO.class);//股东基本信息
                String format = DateUtils.format(viewCompanyRespVO.getFoundDate(), DateUtils.DATE);
                viewCompanyRespVO.setFound(format);
            viewCompanyRespVO.setEnd(DateUtils.format(viewCompanyRespVO.getEndDate(),DateUtils.DATE));
            
            viewCompanyRespVO.setManage(viewCompanyRespVO.getManageLimit());
            if(null != viewCompanyRespVO.getListed()){
                if (viewCompanyRespVO.getListed()==1){
                    viewCompanyRespVO.setListe("是");
                }
                if (viewCompanyRespVO.getListed()==0){
                    viewCompanyRespVO.setListe("否");
                }
            }
            map.put("viewCompanyRespVo",viewCompanyRespVO);
        }
        
        
        
        List<ListHolderRespVO> stockCapitalStruct = objectMapper.readValue(req.getStockCapitalStruct(),
                objectMapper.getTypeFactory().constructParametricType(List.class, ListHolderRespVO.class));//股本结构
        map.put("stockCapitalStruct",stockCapitalStruct);
    
        ViewCompanyRespVO aRealControl =new ViewCompanyRespVO();
        map.put("aRealControl",aRealControl);
        if (null != req.getARealControl() && !req.getARealControl().isEmpty()){
             aRealControl = objectMapper.readValue(req.getARealControl(),ViewCompanyRespVO.class);//股东实控人分析
            String format = DateUtils.format(aRealControl.getFoundDate(), DateUtils.DATE);
            aRealControl.setFound(format);
            aRealControl.setEnd(DateUtils.format(aRealControl.getEndDate(),DateUtils.DATE));
            String date = aRealControl.getManageLimit();
            if (null == date){
                date = "";
            }
            aRealControl.setManage(format+" —— "+date);
            if(null != aRealControl.getListed()){
                if(aRealControl.getListed() == 1){
                    aRealControl.setListe("是");
                }
                if(aRealControl.getListed() == 0){
                    aRealControl.setListe("否");
                }
            }
            map.put("aRealControl",aRealControl);
        }
    
        
        map.put("listPledges",new ArrayList<>());
        map.put("listPledgeDetails",new ArrayList<>());
        map.put("listFreezeDetails",new ArrayList<>());
        if (req.getSharePledge() != null && !req.getSharePledge().isEmpty()){
            ViewStockRightRespVo  sharePledge = objectMapper.readValue(req.getSharePledge(),ViewStockRightRespVo.class);//股东股权质押
    
            List<ViewStockRightRespVo.ListPledge> listPledges = sharePledge.getListPledges();
            listPledges.forEach(l->{
                if (null == l.getStockNum()){
                    l.setStockNum(new BigDecimal(0));
                }
                if(null == l.getPledgeShares()){
                    l.setPledgeShares(new BigDecimal(0));
                }
                if (null == l.getFreezeShares()){
                    l.setFreezeShares(new BigDecimal(0));
                }
            });
            map.put("listPledges",listPledges);
            List<ViewStockRightRespVo.ListPledgeDetail> listPledgeDetail = sharePledge.getListPledgeDetails();
            listPledgeDetail.forEach(a ->{
                if(a.getDischarge() != null){
                    if(a.getDischarge() == 1){
                        a.setRelease("是");
                    }
                    if (a.getDischarge() == 0){
                        a.setRelease("否");
                    }
                } // 股东股权质押 -- 是否解押
                if(a.getEquityPledgeRepo() != null){
                    if(a.getEquityPledgeRepo() == 0){
                        a.setBuyBack("否");
                    }
                    if (a.getEquityPledgeRepo() == 1){
                        a.setBuyBack("是");
                    }
                } //股东股权质押 -- 是否股权质押回购
                if(a.getPledgeBgdate() != null && !a.getPledgeBgdate().isEmpty()){
                   a.setStart(DateUtils.format(new Date(Long.parseLong(a.getPledgeBgdate())),DateUtils.DATE)) ;
                }
                if (a.getPledgeEnddate() != null && !a.getPledgeEnddate().isEmpty()){
                    a.setEnd(DateUtils.format(new Date(Long.parseLong(a.getPledgeEnddate())),DateUtils.DATE));
                }
            });
            map.put("listPledgeDetails",listPledgeDetail);
            List<ViewStockRightRespVo.ListFreezeDetail> listFreezeDetail = sharePledge.getListFreezeDetails();//公司股权冻结明细
            listFreezeDetail.forEach(a ->{
                if(a.getIsTurnFrozen() != null){
                    if(a.getIsTurnFrozen() == 0){
                        a.setFrozen("否");
                        
                    }
                     if(a.getIsTurnFrozen() == 1)   {
                         a.setFrozen("是");
                    }
                } //股东股权质押 -- 是否轮候冻结
                if(a.getIsDisfrozen() != null){
                    if(a.getIsDisfrozen() == 0){
                        a.setThaw("否");
                    }
                    if(a.getIsDisfrozen() == 1){
                        a.setThaw("是");
                    }
                } //股东股权质押 -- 是否解冻
            });
            map.put("listFreezeDetails",listFreezeDetail);
        }
        
        
        List<ListTaxRespVO> taxRating = objectMapper.readValue(req.getTaxRating(),
                objectMapper.getTypeFactory().constructParametricType(List.class, ListTaxRespVO.class));//税务评级
        map.put("taxRating",taxRating);
        
        List<ListCreditRateRespVO> orgRating = objectMapper.readValue(req.getOrgRating(),
                objectMapper.getTypeFactory().constructParametricType(List.class, ListCreditRateRespVO.class));//机构评级
        orgRating.forEach(a ->{
            a.setGradeDate(DateUtils.format(a.getAnnDate(),DateUtils.DATE)); //机构评级 -- 评级日期
        });
        map.put("orgRating",orgRating);
        
        List<ListBankCreditRespVO> bankCredit = objectMapper.readValue(req.getBankCredit(),
                objectMapper.getTypeFactory().constructParametricType(List.class, ListBankCreditRespVO.class));//银行授信
        bankCredit.forEach(a ->{
            a.setNoticeDate(DateUtils.format(a.getAnnDate(),DateUtils.DATE)); //银行授信 -- 公告日期
            a.setFinishDate(DateUtils.format(a.getEndDate(),DateUtils.DATE)); //银行授信 -- 截止日期
            if (a.getCreditUnused() != null && "0E-8".equals(a.getCreditUnused().toString())){
                a.setCreditUnused(new BigDecimal(0));
            }
        });
        map.put("bankCredit",bankCredit);
    
        ListOneselfRiskRespVO selfRisk = new ListOneselfRiskRespVO();
        map.put("selfRisk",selfRisk);
        if (req.getSelfRisk() != null && !req.getSelfRisk().isEmpty()){
            selfRisk = objectMapper.readValue(req.getSelfRisk(),ListOneselfRiskRespVO.class);//selfRisk  自身风险
            selfRisk.getQueryByRiskTypeRespDTO().forEach(a ->{
                a.setProductionDate(DateUtils.format(a.getBuildTime(),DateUtils.DATE));
                if (null != a.getRiskContent()){
                    a.setRiskContent(a.getRiskContent().replaceAll("<br/>",""));
                }
            });
            map.put("selfRisk",selfRisk);
            if(selfRisk.getQueryCompRiskTypeRespVO().getRedRiskType() != null ){
                List<RedRiskType> reds = new ArrayList<>();
                selfRisk.getQueryCompRiskTypeRespVO().getRedRiskType().forEach(r->{
                    RedRiskType red = new RedRiskType();
                    red.setRed(r);
                    red.setColor("红色");
                    reds.add(red);
                });
                map.put("red",reds);
            }
            if(selfRisk.getQueryCompRiskTypeRespVO().getYellowRiskType() != null){
                List<YellowRiskType> list = new ArrayList<>();
                selfRisk.getQueryCompRiskTypeRespVO().getYellowRiskType().forEach(y->{
                    YellowRiskType yellowRiskType = new YellowRiskType();
                    yellowRiskType.setYellow(y);
                    yellowRiskType.setColor("黄色");
                    list.add(yellowRiskType);
                });
                map.put("yellow",list);
            }
            QueryCompRiskTypeRespVO queryCompRiskTypeRespVO = selfRisk.getQueryCompRiskTypeRespVO();
            if(null != queryCompRiskTypeRespVO.getRed()){
                queryCompRiskTypeRespVO.setR(queryCompRiskTypeRespVO.getRed().toString());
            }else {
                queryCompRiskTypeRespVO.setY("0");
            }
            if(null != queryCompRiskTypeRespVO.getYellow()){
                queryCompRiskTypeRespVO.setY(queryCompRiskTypeRespVO.getYellow().toString());
            }else {
                queryCompRiskTypeRespVO.setY("0");
            }
            
            
            map.put("queryCompRiskTypeRespVO",queryCompRiskTypeRespVO);
            map.put("queryByRiskTypeRespDTO",selfRisk.getQueryByRiskTypeRespDTO());
        }
        
        
        List<QueryCompAssociateDTO> relRisk = objectMapper.readValue(req.getRelRisk(),
                objectMapper.getTypeFactory().constructParametricType(List.class, QueryCompAssociateDTO.class));//关联风险
        relRisk.forEach(a ->{
            a.setProduction(DateUtils.format(a.getBuildTime(),DateUtils.DATE)); //关联风险 -- 产生时间
            if(a.getConnection() != null){
                if(a.getConnection() == 1){
                    a.setHops("一级关联");
                }else if(a.getConnection() == 2){
                    a.setHops("二级关联");
                }else if(a.getConnection() == 3){
                    a.setHops("三级关联");
                }
            
            } //关联风险 -- 跳数
            
            if(null != a.getRiskContent()){
                a.setRiskContent(a.getRiskContent().replaceAll("<br/>",""));
            }
        });
        map.put("relRisk",relRisk);
        
        List<ListSubsidiaryDTO> subBaseInfo = objectMapper.readValue(req.getSubBaseInfo(),
                objectMapper.getTypeFactory().constructParametricType(List.class, ListSubsidiaryDTO.class));//子公司基本信息
        subBaseInfo.forEach(a ->{
            a.setEstablishDate(DateUtils.format(a.getFoundDate(),DateUtils.DATE)); //子公司基本信息 -- 成立日期
            if(a.getVie() != null){
                if(a.getVie() == 1){
                    a.setControl("是");
                }
                if (a.getVie() == 0){
                    a.setControl("否");
                }
            } //子公司基本信息 -- 是否VIE(协议控制)
            if(a.getProfit() != null){
                if(a.getProfit() == 1){
                    a.setTransaction("是");
                }
                if (a.getProfit() == 0){
                    a.setTransaction("否");
                }
            } //子公司基本信息 -- 是否盈利(交易所)
        });
        map.put("subBaseInfo",subBaseInfo);
        
        
        List<ListHolderRespVO> subStockInfo = objectMapper.readValue(req.getSubStockInfo(),
                objectMapper.getTypeFactory().constructParametricType(List.class, ListHolderRespVO.class));//子公司股东信息
        subStockInfo.forEach(a ->{
            a.setNoticeDate(DateUtils.format(a.getAnnDate(),DateUtils.DATE)); //子公司股东信息 -- 公告日期
            if(a.getControllerIsAnn() != null){
                if(a.getControllerIsAnn() == 1){
                    a.setControlAnn("是");
                }else{
                    a.setControlAnn("否");
                }
            } //子公司股东信息 -- 股东是否为公布实际控制人
            if(a.getControlSharehol() != null){
                if(a.getControlSharehol() == 1){
                    a.setShareholder("是");
                }else{
                    a.setShareholder("否");
                }
            } //子公司股东信息 -- 股东是否为公布控股股东
        });
        map.put("subStockInfo",subStockInfo);
        
        
        List<ListFinanceCostsRespVO> costRate = objectMapper.readValue(req.getCostRate(),
                objectMapper.getTypeFactory().constructParametricType(List.class, ListFinanceCostsRespVO.class));//融资成本率
        map.put("costRate",costRate);
        
        
        List<ListBondFinanceRespVO> stockCapital = objectMapper.readValue(req.getStockCapital(),
                objectMapper.getTypeFactory().constructParametricType(List.class, ListBondFinanceRespVO.class));//债股融资
        stockCapital.forEach(a ->{
            a.setNoticeDate(DateUtils.format(a.getAnnDate(),DateUtils.DATE));//债股融资 -- 公告日期
        });
        map.put("stockCapital",stockCapital);
        
        
        List<ListDebitCreditRespVO> debtCreditRecord = objectMapper.readValue(req.getDebtCreditRecord(),
                objectMapper.getTypeFactory().constructParametricType(List.class, ListDebitCreditRespVO.class));//借贷记录
        debtCreditRecord.forEach(a ->{
            a.setNoticeDate(DateUtils.format(a.getReleaseDate(),DateUtils.DATE));//借贷记录 -- 发布日期
        });
        map.put("debtCreditRecord",debtCreditRecord);
        
        List<ListGuaranteeRespVO> guaranteeRecord = objectMapper.readValue(req.getGuaranteeRecord(),
                objectMapper.getTypeFactory().constructParametricType(List.class, ListGuaranteeRespVO.class));//担保记录
        guaranteeRecord.forEach(a ->{
            a.setNoticeDate(DateUtils.format(a.getReportPeriod(),DateUtils.DATE));//担保记录 -- 报告期
        });
        map.put("guaranteeRecord",guaranteeRecord);
        
        
        List<ListInvestRespVO> investInfo = objectMapper.readValue(req.getInvestInfo(),
                objectMapper.getTypeFactory().constructParametricType(List.class, ListInvestRespVO.class));//投资基本情况
        investInfo.forEach(a ->{
            a.setEstablishDate(DateUtils.format(a.getFoundDate(),DateUtils.DATE));//投资基本情况 -- 成立日期
            if(null != a.getInvestRatio())
            a.setInvestRatio(a.getInvestRatio().setScale(2, BigDecimal.ROUND_HALF_UP));
            if (null != a.getSubscribedCapital())
            a.setSubscribedCapital(a.getSubscribedCapital().substring(0,a.getSubscribedCapital().length()-2));
            if (null != a.getInvestRegCapital())
            a.setInvestRegCapital(a.getInvestRegCapital().setScale(2, BigDecimal.ROUND_HALF_UP));
        });
        map.put("investInfo",investInfo);
        XWPFDocument document = WordExportUtil.exportWord07(path, map);
        Map<String, POIXMLDocumentPart> charts = doCharts(document);

        if(manageInfo != null){
            if(null != manageInfo.getListOperationRespVOS() && !manageInfo.getListOperationRespVOS().isEmpty()
            ){
                doCharts1(charts,manageInfo.getListOperationRespVOS());
                doCharts2(charts,manageInfo.getListOperationRespVOS());
                doCharts3(charts,manageInfo.getListOperationRespVOS());
                doCharts4(charts,manageInfo.getListOperationRespVOS());
            }
        }
        
       
        if(!mainBusiness.getMainBusinesses().isEmpty()){
            doCharts5(charts,mainBusiness.getMainBusinesses());
        }
        if(null != aBalanceStructVO.getListAssetStructRespVOS()){
            doCharts6(charts,aBalanceStructVO.getListAssetStructRespVOS());
            doCharts7(charts,aBalanceStructVO.getListAssetStructRespVOS());
            doCharts8(charts,aBalanceStructVO.getListAssetStructRespVOS());
            doCharts9(charts,aBalanceStructVO.getListAssetStructRespVOS());
           
        }
        if(null != aProfitStructVO.getListProfitStructRespVOS()){
            doCharts10(charts,aProfitStructVO.getListProfitStructRespVOS());
            doCharts11(charts,aProfitStructVO.getListProfitStructRespVOS());
        }
        
        if(null != aCashStructVO.getListCashStructRespVOS()){
            doCharts12(charts,aCashStructVO.getListCashStructRespVOS());
            doCharts13(charts,aCashStructVO.getListCashStructRespVOS());
        }
        if(null != costRate){
            doCharts14(charts,costRate);
            doCharts14(charts,costRate);
        }
        
        WordExportUtils.wordExport(module.getName(),document);
        String pathUrl = DIRECTORY+System.currentTimeMillis()+".docx";
        OutputStream out = new FileOutputStream(pathUrl);
        document.write(out);
        out.close();
        File file = new File(pathUrl);
        String upload = create+DateUtils.format(new Date(),DateUtils.DATE);
        String uploadPath = fileService.upload(file, upload);
        req.setPath(uploadPath);
        selfReportService.modifyById(req);
        return uploadPath;
        
        
    }
    
    public  Map<String, POIXMLDocumentPart> doCharts(XWPFDocument doc) throws FileNotFoundException {
        
        Map<String, POIXMLDocumentPart> chartsMap = new HashMap<String, POIXMLDocumentPart>();
        List<POIXMLDocumentPart> relations = doc.getRelations();
        for (POIXMLDocumentPart poixmlDocumentPart : relations) {
            if (poixmlDocumentPart instanceof XWPFChart) {
                
                String str = poixmlDocumentPart.toString();
                String key = str.replaceAll("Name: ", "")
                        .replaceAll(" - Content Type: application/vnd\\.openxmlformats-officedocument\\.drawingml\\.chart\\+xml", "").trim();
                chartsMap.put(key, poixmlDocumentPart);
            }
        }
        return chartsMap;
    }
    
    //营业收入
    private void doCharts1(Map<String, POIXMLDocumentPart> chartsMap,List<ListOperationRespVO> list){
        List<String> titleArr = new ArrayList<String>();// 标题
        titleArr.add("");
        titleArr.add("营收金额(万元)");
        titleArr.add("同比增长(%)");
    
        List<String> fldNameArr = new ArrayList<String>();// 字段名(数据有多少列，就多少个)
        fldNameArr.add("item1");
        fldNameArr.add("item2");
        fldNameArr.add("item3");
        List<Map<String, String>> listItemsByType = new ArrayList<Map<String, String>>();
        if ( null != list && !list.isEmpty() ){
            for (ListOperationRespVO listOperationRespVO : list) {
                Map<String,String> base = new HashMap<String,String>();
                if (listOperationRespVO.getYear()!= null && !listOperationRespVO.getYear().isEmpty()){
                    base.put("item1",listOperationRespVO.getYear());
                }else{
                    base.put("item1","");
                }
                if (listOperationRespVO.getOperRev()!= null){
                    base.put("item2",listOperationRespVO.getOperRev().toString());
                }else{
                    base.put("item2","0");
                }
                if (listOperationRespVO.getSalesGrow()!= null){
                    base.put("item3",listOperationRespVO.getSalesGrow().toString());
                }else{
                    base.put("item3","0");
                }
                listItemsByType.add(base);
            }
        }
    
        if (!listItemsByType.isEmpty()){
            POIXMLDocumentPart poixmlDocumentPart = chartsMap.get("/word/charts/chart1.xml");
            replaceCombinationCharts(poixmlDocumentPart, titleArr, fldNameArr, listItemsByType);
        }
        
    }
    
    
    //净利润
    private void doCharts2(Map<String, POIXMLDocumentPart> chartsMap,List<ListOperationRespVO> list){
        List<String> titleArr = new ArrayList<String>();// 标题
        titleArr.add("");
        titleArr.add("净利润(万元)");
        titleArr.add("同比增长(%)");
    
        List<String> fldNameArr = new ArrayList<String>();// 字段名(数据有多少列，就多少个)
        fldNameArr.add("item1");
        fldNameArr.add("item2");
        fldNameArr.add("item3");
    
        List<Map<String, String>> listItemsByType = new ArrayList<Map<String, String>>();
        if ( null != list && !list.isEmpty()){
            for (ListOperationRespVO listOperationRespVO : list) {
                Map<String,String> base = new HashMap<String,String>();
                if (listOperationRespVO.getYear()!= null && !listOperationRespVO.getYear().isEmpty()){
                    base.put("item1",listOperationRespVO.getYear());
                }else{
                    base.put("item1","");
                }
                if (listOperationRespVO.getNetProfitInclMinIntInc() != null){
                    base.put("item2",listOperationRespVO.getNetProfitInclMinIntInc().toString());
                }else{
                    base.put("item2","0");
                }
                if (listOperationRespVO.getProfitGrow() != null){
                    base.put("item3",listOperationRespVO.getProfitGrow().toString());
                }else{
                    base.put("item3","0");
                }
                listItemsByType.add(base);
            }
            if (!listItemsByType.isEmpty()){
                POIXMLDocumentPart poixmlDocumentPart = chartsMap.get("/word/charts/chart2.xml");
                replaceCombinationCharts(poixmlDocumentPart, titleArr, fldNameArr, listItemsByType);
            }
        }
        
        
    }
    
    //总资产
    private void doCharts3(Map<String, POIXMLDocumentPart> chartsMap,List<ListOperationRespVO> list) {
        List<String> titleArr = new ArrayList<String>();// 标题
        titleArr.add("");
        titleArr.add("总资产(万元)");
        titleArr.add("同比增长(%)");
    
        List<String> fldNameArr = new ArrayList<String>();// 字段名(数据有多少列，就多少个)
        fldNameArr.add("item1");
        fldNameArr.add("item2");
        fldNameArr.add("item3");
    
        List<Map<String, String>> listItemsByType = new ArrayList<Map<String, String>>();
        if (null != list && !list.isEmpty()){
            for (ListOperationRespVO listOperationRespVO : list) {
                Map<String,String> base = new HashMap<String,String>();
                if (listOperationRespVO.getYear() != null && !listOperationRespVO.getYear().isEmpty()){
                    base.put("item1",listOperationRespVO.getYear());
                }else{
                    base.put("item1","");
                }
                if(listOperationRespVO.getTotAssets() != null){
                    base.put("item2",listOperationRespVO.getTotAssets().toString());
                }else{
                    base.put("item2","0");
                }
                if (listOperationRespVO.getTotalAssetGrow() != null){
                    base.put("item3",listOperationRespVO.getTotalAssetGrow().toString());
                }else{
                    base.put("item3","0");
                }
                
                listItemsByType.add(base);
            }
            if (!listItemsByType.isEmpty()){
                POIXMLDocumentPart poixmlDocumentPart = chartsMap.get("/word/charts/chart3.xml");
                replaceCombinationCharts(poixmlDocumentPart, titleArr, fldNameArr, listItemsByType);
            }
        }
        
        
    }
    
    
    //净资产
    private void doCharts4(Map<String, POIXMLDocumentPart> chartsMap,List<ListOperationRespVO> list) {
        List<String> titleArr = new ArrayList<String>();// 标题
        titleArr.add("");
        titleArr.add("净资产(万元)");
        titleArr.add("同比增长(%)");
    
        List<String> fldNameArr = new ArrayList<String>();// 字段名(数据有多少列，就多少个)
        fldNameArr.add("item1");
        fldNameArr.add("item2");
        fldNameArr.add("item3");
    
        List<Map<String, String>> listItemsByType = new ArrayList<Map<String, String>>();
        if (null != list && !list.isEmpty()){
            for (ListOperationRespVO listOperationRespVO : list) {
                Map<String,String> base = new HashMap<String,String>();
                if (listOperationRespVO.getYear() != null && !listOperationRespVO.getYear().isEmpty()){
                    base.put("item1",listOperationRespVO.getYear());
                }else{
                    base.put("item1","");
                }
                if(listOperationRespVO.getTotNonCurAssets() != null){
                    base.put("item2",listOperationRespVO.getTotNonCurAssets().toString());
                }else{
                    base.put("item2","0");
                }
                if (listOperationRespVO.getCapitalGrow() != null){
                    base.put("item3",listOperationRespVO.getCapitalGrow().toString());
                }else{
                    base.put("item3","0");
                }
                
                listItemsByType.add(base);
            }
            if (!listItemsByType.isEmpty()){
                POIXMLDocumentPart poixmlDocumentPart = chartsMap.get("/word/charts/chart4.xml");
                replaceCombinationCharts(poixmlDocumentPart, titleArr, fldNameArr, listItemsByType);
            }
        }
        
        
    }
    
    
    private void doCharts5(Map<String, POIXMLDocumentPart> chartsMap,List<MainBusiness> list){
        List<String> titleArr = new ArrayList<String>();// 标题
        titleArr.add("");
        titleArr.add("核心业务销售额（万元）");
        titleArr.add("占总营收比例（%）");
        titleArr.add("销售额增长率（%）");
    
        List<String> fldNameArr = new ArrayList<String>();// 字段名(数据有多少列，就多少个)
        fldNameArr.add("item1");
        fldNameArr.add("item2");
        fldNameArr.add("item3");
        fldNameArr.add("item4");
    
        List<Map<String, String>> listItemsByType = new ArrayList<Map<String, String>>();
        if (null != list && !list.isEmpty()){
            for (MainBusiness mainBusiness : list) {
                Map<String,String> map = new HashMap<>();
                if (mainBusiness.getReportPeriod() != null && !mainBusiness.getReportPeriod().isEmpty()){
                    map.put("item1",mainBusiness.getTime());
                }else{
                    map.put("item1","");
                }
                if (mainBusiness.getSegmentSales()!= null){
                    map.put("item2",mainBusiness.getSegmentSales().toString());
                }else{
                    map.put("item2","0");
                }
                if (mainBusiness.getSegmentSaleRatio() != null){
                    map.put("item3",mainBusiness.getSegmentSaleRatio().toString());
                }else{
                    map.put("item3","0");
                }
                if(mainBusiness.getPrimeOperRevYoy() != null){
                    map.put("item4",mainBusiness.getPrimeOperRevYoy().toString());
                }else{
                    map.put("item4","0");
                }
                listItemsByType.add(map);
            }
            if (!listItemsByType.isEmpty()){
                POIXMLDocumentPart poixmlDocumentPart = chartsMap.get("/word/charts/chart5.xml");
                replaceCombinationCharts(poixmlDocumentPart, titleArr, fldNameArr, listItemsByType);
            }
        }
        
        
        
        
        
    }
    
    //资产流动性结构
    private void doCharts6(Map<String, POIXMLDocumentPart> chartsMap,ListAssetStructRespVO list){
        List<String> titleArr = new ArrayList<String>();// 标题
        titleArr.add("");
        titleArr.add("资产流动性结构");
    
        List<String> fldNameArr = new ArrayList<String>();// 字段名(数据有多少列，就多少个)
        fldNameArr.add("item1");
        fldNameArr.add("item2");
        List<Map<String, String>> listItemsByType = new ArrayList<Map<String, String>>();
        if(null != list){
            if (list.getNonAssetsRate() != null ){
                Map<String,String> map1 = new HashMap<>();
                map1.put("item1","非流动资产");
                map1.put("item2",list.getNonAssetsRate().toString());
                listItemsByType.add(map1);
            }
            if (list.getCurAssetsRate() != null){
                Map<String,String> map2 = new HashMap<>();
                map2.put("item1","流动资产");
                map2.put("item2",list.getCurAssetsRate().toString());
        
                listItemsByType.add(map2);
            }
            if (!listItemsByType.isEmpty()){
                POIXMLDocumentPart poixmlDocumentPart = chartsMap.get("/word/charts/chart6.xml");
                replacePieCharts(poixmlDocumentPart, titleArr, fldNameArr, listItemsByType);
            }
        }
        
        
    }
    
    //负债流动性结构
    private void doCharts7(Map<String, POIXMLDocumentPart> chartsMap,ListAssetStructRespVO list){
        List<String> titleArr = new ArrayList<String>();// 标题
        titleArr.add("");
        titleArr.add("负债流动性结构");
        
        List<String> fldNameArr = new ArrayList<String>();// 字段名(数据有多少列，就多少个)
        fldNameArr.add("item1");
        fldNameArr.add("item2");
        List<Map<String, String>> listItemsByType = new ArrayList<Map<String, String>>();
        if (null!=list){
            BigDecimal nonLiabRate = list.getNonLiabRate();
            BigDecimal curLiabRate = list.getCurLiabRate();
            if (null != nonLiabRate){
                Map<String,String> map1 = new HashMap<>();
                map1.put("item1","非流动负债");
                map1.put("item2",list.getNonLiabRate().toString());
                listItemsByType.add(map1);
            }
            if (null != curLiabRate){
                Map<String,String> map2 = new HashMap<>();
                map2.put("item1","流动负债");
                map2.put("item2",list.getCurLiabRate().toString());
                listItemsByType.add(map2);
            }
    
            if (!listItemsByType.isEmpty()){
                POIXMLDocumentPart poixmlDocumentPart = chartsMap.get("/word/charts/chart7.xml");
                replacePieCharts(poixmlDocumentPart, titleArr, fldNameArr, listItemsByType);
            }
        }
        
    }
    
    //流动资产结构分析
    private void doCharts8(Map<String, POIXMLDocumentPart> chartsMap,ListAssetStructRespVO list){
        List<String> titleArr = new ArrayList<String>();// 标题
        titleArr.add("");
        titleArr.add("流动资产结构分析");
        
        List<String> fldNameArr = new ArrayList<String>();// 字段名(数据有多少列，就多少个)
        fldNameArr.add("item1");
        fldNameArr.add("item2");
        List<Map<String, String>> listItemsByType = new ArrayList<Map<String, String>>();
        if (null != list){
            if (list.getCashFundRate() != null){
                Map<String,String> map1 = new HashMap<>();
                map1.put("item1","货币资金");
                map1.put("item2",list.getCashFundRate().toString());
                listItemsByType.add(map1);
            }
            if (list.getTradeAssetRate() != null){
                Map<String,String> map2 = new HashMap<>();
                map2.put("item1","交易性金融资产");
                map2.put("item2",list.getTradeAssetRate().toString());
                listItemsByType.add(map2);
            }
    
            if (list.getReceivableRate() != null){
                Map<String,String> map3 = new HashMap<>();
                map3.put("item1","应收账款");
                map3.put("item2",list.getReceivableRate().toString());
                listItemsByType.add(map3);
            }
    
            if (list.getInventoryRate() != null){
                Map<String,String> map4 = new HashMap<>();
                map4.put("item1","存货");
                map4.put("item2",list.getInventoryRate().toString());
                listItemsByType.add(map4);
            }
            if (list.getAdvanceRate() != null){
                Map<String,String> map5 = new HashMap<>();
                map5.put("item1","预付款项");
                map5.put("item2",list.getAdvanceRate().toString());
                listItemsByType.add(map5);
            }
            if (list.getOtherReceivableRate() != null){
                Map<String,String> map6 = new HashMap<>();
                map6.put("item1","其他应收款");
                map6.put("item2",list.getOtherReceivableRate().toString());
                listItemsByType.add(map6);
            }
            if (list.getHeldSaleRate() != null){
                Map<String,String> map7 = new HashMap<>();
                map7.put("item1","持有待售资产");
                map7.put("item2",list.getHeldSaleRate().toString());
                listItemsByType.add(map7);
            }
            if (list.getNonCurAssets1yRate() != null){
                Map<String,String> map8 = new HashMap<>();
                map8.put("item1","一年内到期的非流动资产");
                map8.put("item2",list.getNonCurAssets1yRate().toString());
                listItemsByType.add(map8);
            }
            if (list.getOthCurAssetsRate() != null){
                Map<String,String> map9 = new HashMap<>();
                map9.put("item1","其他流动资产");
                map9.put("item2",list.getOthCurAssetsRate().toString());
                listItemsByType.add(map9);
            }
            if (list.getOtherAssetRate() != null){
                Map<String,String> map10 = new HashMap<>();
                map10.put("item1","其他");
                map10.put("item2",list.getOtherAssetRate().toString());
                listItemsByType.add(map10);
            }
            if (!listItemsByType.isEmpty()){
                POIXMLDocumentPart poixmlDocumentPart = chartsMap.get("/word/charts/chart8.xml");
                replacePieCharts(poixmlDocumentPart, titleArr, fldNameArr, listItemsByType);
            }
        }
        
    }
    
 
    //非流动资产结构分析
    private void doCharts9(Map<String, POIXMLDocumentPart> chartsMap,ListAssetStructRespVO list){
        if(null != list){
            List<String> titleArr = new ArrayList<String>();// 标题
            titleArr.add("");
            titleArr.add("非流动资产结构分析");
        
            List<String> fldNameArr = new ArrayList<String>();// 字段名(数据有多少列，就多少个)
            fldNameArr.add("item1");
            fldNameArr.add("item2");
            List<Map<String, String>> listItemsByType = new ArrayList<Map<String, String>>();
            
            
            if(list.getFinAssetsAvailRate() != null){
                Map<String, String> map1=new HashMap<>();
                map1.put("item1","可供出售金融资产");
                map1.put("item2",list.getFinAssetsAvailRate().toString());
                listItemsByType.add(map1);
            }
            if(list.getHeldToMtyInvestRate() != null){
                Map<String, String> map2=new HashMap<>();
                map2.put("item1","持有至到期投资");
                map2.put("item2",list.getHeldToMtyInvestRate().toString());
                listItemsByType.add(map2);
            }
            if(list.getLongTermRecRate() != null){
                Map<String, String> map3=new HashMap<>();
                map3.put("item1","长期应收款");
                map3.put("item2",list.getLongTermRecRate().toString());
                listItemsByType.add(map3);
            }
            if(list.getLongTermEqyInvestRate() != null){
                Map<String, String> map4=new HashMap<>();
                map4.put("item1","长期股权投资");
                map4.put("item2",list.getLongTermEqyInvestRate().toString());
                listItemsByType.add(map4);
            }
            if(list.getInvestRealEstateRate() != null){
                Map<String, String> map5=new HashMap<>();
                map5.put("item1","投资性房地产");
                map5.put("item2",list.getInvestRealEstateRate().toString());
                listItemsByType.add(map5);
            }
            if(list.getFixAssetsRate() != null){
                Map<String, String> map6=new HashMap<>();
                map6.put("item1","固定资产");
                map6.put("item2",list.getFixAssetsRate().toString());
                listItemsByType.add(map6);
            }
            if(list.getIntangAssetsRate() != null){
                Map<String, String> map7=new HashMap<>();
                map7.put("item1","无形资产");
                map7.put("item2",list.getIntangAssetsRate().toString());
                listItemsByType.add(map7);
            }
            if(list.getConstInProgTotRate() != null){
                Map<String, String> map8=new HashMap<>();
                map8.put("item1","在建工程");
                map8.put("item2",list.getConstInProgTotRate().toString());
                listItemsByType.add(map8);
            }
            if(list.getOtherRate() != null){
                Map<String, String> map9=new HashMap<>();
                map9.put("item1","其他");
                map9.put("item2",list.getOtherRate().toString());
                listItemsByType.add(map9);
            }
            if (!listItemsByType.isEmpty()){
                POIXMLDocumentPart poixmlDocumentPart = chartsMap.get("/word/charts/chart9.xml");
                replacePieCharts(poixmlDocumentPart, titleArr, fldNameArr, listItemsByType);
            }
        }
    }
    
    //利润结构分析
    private void doCharts10(Map<String, POIXMLDocumentPart> chartsMap, ListProfitStructRespVO list){
        List<String> titleArr = new ArrayList<String>();// 标题
        titleArr.add("");
        titleArr.add("利润结构分析");
        
        List<String> fldNameArr = new ArrayList<String>();// 字段名(数据有多少列，就多少个)
        fldNameArr.add("item1");
        fldNameArr.add("item2");
        List<Map<String, String>> listItemsByType = new ArrayList<Map<String, String>>();
        if( null != list){
            if (list.getOperProfit() != null){
                Map<String, String> map1=new HashMap<>();
                map1.put("item1","营业利润");
                map1.put("item2",list.getOperProfit().toString());
                listItemsByType.add(map1);
            }
            if (list.getPlusNonOperRev()!= null){
                Map<String, String> map2=new HashMap<>();
        
                map2.put("item1","营业外收支净额");
                map2.put("item2",list.getPlusNonOperRev().toString());
        
        
                listItemsByType.add(map2);
            }
    
            if (!listItemsByType.isEmpty()){
                POIXMLDocumentPart poixmlDocumentPart = chartsMap.get("/word/charts/chart10.xml");
                replacePieCharts(poixmlDocumentPart, titleArr, fldNameArr, listItemsByType);
            }
        }
       
    }
    
    
    //营业成本结构分析
  
    private void doCharts11(Map<String, POIXMLDocumentPart> chartsMap, ListProfitStructRespVO list){
 
        List<String> titleArr = new ArrayList<String>();// 标题
        titleArr.add("");
        titleArr.add("营业成本结构分析");
    
        List<String> fldNameArr = new ArrayList<String>();// 字段名(数据有多少列，就多少个)
        fldNameArr.add("item1");
        fldNameArr.add("item2");
        List<Map<String, String>> listItemsByType = new ArrayList<Map<String, String>>();
        if( null != list){
            if(list.getSalesCost() != null){
                Map<String, String> map1=new HashMap<>();
                map1.put("item1","主营业务成本");
                map1.put("item2",list.getSalesCost().toString());
                listItemsByType.add(map1);
            }
            if(list.getLessTaxesSurchargesOps() != null){
                Map<String, String> map2=new HashMap<>();
                map2.put("item1","税金及附加");
                map2.put("item2",list.getLessTaxesSurchargesOps().toString());
                listItemsByType.add(map2);
            }
            if(list.getRdExpense() != null){
                Map<String, String> map3=new HashMap<>();
                map3.put("item1","研发费用");
                map3.put("item2",list.getRdExpense().toString());
                listItemsByType.add(map3);
            }
            if(list.getFinExp() != null){
                Map<String, String> map4=new HashMap<>();
                map4.put("item1","财务费用占比");
                map4.put("item2",list.getFinExp().toString());
                listItemsByType.add(map4);
            }
            if(list.getSellingDistExp() != null){
                Map<String, String> map5=new HashMap<>();
                map5.put("item1","销售费用");
                map5.put("item2",list.getSellingDistExp().toString());
                listItemsByType.add(map5);
            }
            if(list.getGerlAdminExp() != null){
                Map<String, String> map6=new HashMap<>();
                map6.put("item1","管理费用");
                map6.put("item2",list.getGerlAdminExp().toString());
                listItemsByType.add(map6);
            }
    
    
            if (!listItemsByType.isEmpty()){
                POIXMLDocumentPart poixmlDocumentPart = chartsMap.get("/word/charts/chart11.xml");
                replacePieCharts(poixmlDocumentPart, titleArr, fldNameArr, listItemsByType);
            }
        }
        
        
    }
    //现金流入结构分析
    private void doCharts12(Map<String, POIXMLDocumentPart> chartsMap, ListCashStructRespVO list){
        
        List<String> titleArr = new ArrayList<String>();// 标题
        titleArr.add("");
        titleArr.add("现金流入结构分析");
    
        List<String> fldNameArr = new ArrayList<String>();// 字段名(数据有多少列，就多少个)
        fldNameArr.add("item1");
        fldNameArr.add("item2");
    
        List<Map<String, String>> listItemsByType = new ArrayList<Map<String, String>>();
    
        if( null != list){
            if(list.getStotCashInflowsFncAct() != null){
                Map<String, String> map1=new HashMap<>();
                map1.put("item1","筹资活动");
                map1.put("item2",list.getStotCashInflowsFncAct().toString());
                listItemsByType.add(map1);
            }
            if(list.getStotCashInflowsOperAct() != null){
                Map<String, String> map3=new HashMap<>();
                map3.put("item1","经营活动");
                map3.put("item2",list.getStotCashInflowsOperAct().toString());
                listItemsByType.add(map3);
            }
            if(list.getStotCashInflowsInvAct() != null){
                Map<String, String> map2=new HashMap<>();
                map2.put("item1","投资活动");
                map2.put("item2",list.getStotCashInflowsInvAct().toString());
                listItemsByType.add(map2);
            }
            if (!listItemsByType.isEmpty()){
                POIXMLDocumentPart poixmlDocumentPart = chartsMap.get("/word/charts/chart12.xml");
                replacePieCharts(poixmlDocumentPart, titleArr, fldNameArr, listItemsByType);
            }
        }
    
        
        
    }
    
    //现金流出结构分析
    private void doCharts13(Map<String, POIXMLDocumentPart> chartsMap, ListCashStructRespVO list){
        if(null != list){
            List<String> titleArr = new ArrayList<String>();// 标题
            titleArr.add("");
            titleArr.add("现金流出结构分析");
            
            List<String> fldNameArr = new ArrayList<String>();// 字段名(数据有多少列，就多少个)
            fldNameArr.add("item1");
            fldNameArr.add("item2");
            
            List<Map<String, String>> listItemsByType = new ArrayList<Map<String, String>>();
    
          
            if(list.getStotCashOutflowsFncAct() != null){
                Map<String, String> map1=new HashMap<>();
                map1.put("item1","筹资活动");
                map1.put("item2",list.getStotCashOutflowsFncAct().toString());
                listItemsByType.add(map1);
            }
            if(list.getStotCashOutflowsOperAct() != null){
                Map<String, String> map3=new HashMap<>();
                map3.put("item1","经营活动");
                map3.put("item2",list.getStotCashOutflowsOperAct().toString());
                listItemsByType.add(map3);
            }
            if(list.getStotCashOutflowsOperAct() != null){
                Map<String, String> map2=new HashMap<>();
                map2.put("item1","投资活动");
                map2.put("item2",list.getStotCashOutflowsInvAct().toString());
                listItemsByType.add(map2);
            }
    
    
            if (!listItemsByType.isEmpty()){
                POIXMLDocumentPart poixmlDocumentPart = chartsMap.get("/word/charts/chart13.xml");
                replacePieCharts(poixmlDocumentPart, titleArr, fldNameArr, listItemsByType);
            }
        }
    }
    
    
    
    //融资成本率
    private void doCharts14(Map<String, POIXMLDocumentPart> chartsMap, List<ListFinanceCostsRespVO> list){
        if(null != list && !list.isEmpty()){
            List<String> titleArr = new ArrayList<String>();// 标题
            titleArr.add("");
            titleArr.add("年均融资利率（%）");
            
            List<String> fldNameArr = new ArrayList<String>();// 字段名(数据有多少列，就多少个)
            fldNameArr.add("item1");
            fldNameArr.add("item2");
            
            List<Map<String, String>> listItemsByType = new ArrayList<Map<String, String>>();
            if (null != list && !list.isEmpty()){
                for (ListFinanceCostsRespVO listFinanceCostsRespVO : list) {
                    Map<String,String> map = new HashMap<>();
                    if(listFinanceCostsRespVO.getYear() != null){
                        map.put("item1",listFinanceCostsRespVO.getYear());
                    }else{
                        map.put("item1","");
                    }
                    if(listFinanceCostsRespVO.getRate() != null){
                        map.put("item2",listFinanceCostsRespVO.getRate().toString());
                    }else{
                        map.put("item2","0");
                    }
                    listItemsByType.add(map);
                }
            }
    
    
            if (!listItemsByType.isEmpty()){
                POIXMLDocumentPart poixmlDocumentPart = chartsMap.get("/word/charts/chart14.xml");
                replaceLineCharts(poixmlDocumentPart, titleArr, fldNameArr, listItemsByType);
            }
        }
    }
    
    public static void replaceLineCharts(POIXMLDocumentPart poixmlDocumentPart, List<String> titleArr, List<String> fldNameArr, List<Map<String, String>> listItemsByType) {
        XWPFChart chart = (XWPFChart) poixmlDocumentPart;
        chart.getCTChart();
        
        //根据属性第一列名称切换数据类型
        CTChart ctChart = chart.getCTChart();
        CTPlotArea plotArea = ctChart.getPlotArea();
        
        CTLineChart lineChart = plotArea.getLineChartArray(0);
        List<CTLineSer> lineSerList = lineChart.getSerList();   // 获取折线图单位
        
        //刷新内置excel数据
        refreshExcel(chart, listItemsByType, fldNameArr, titleArr);
        //刷新页面显示数据
        refreshLineStrGraphContent(lineChart, lineSerList, listItemsByType, fldNameArr, 1);
        
    }
    
    public static void replaceCombinationCharts(POIXMLDocumentPart poixmlDocumentPart,
            List<String> titleArr, List<String> fldNameArr, List<Map<String, String>> listItemsByType) {
        XWPFChart chart = (XWPFChart) poixmlDocumentPart;
        chart.getCTChart();
        
        //根据属性第一列名称切换数据类型
        CTChart ctChart = chart.getCTChart();
        CTPlotArea plotArea = ctChart.getPlotArea();
        
        
        CTBarChart barChart = plotArea.getBarChartArray(0);
        List<CTBarSer> barSerList = barChart.getSerList();  // 获取柱状图单位
        //刷新内置excel数据
        refreshExcel(chart, listItemsByType, fldNameArr, titleArr);
        //刷新页面显示数据   数据中下标1开始的是柱状图数据，所以这个是1
        refreshBarStrGraphContent(barChart, barSerList, listItemsByType, fldNameArr, 1);
        
        
        CTLineChart lineChart = plotArea.getLineChartArray(0);
        List<CTLineSer> lineSerList = lineChart.getSerList();   // 获取折线图单位
        //刷新内置excel数据   有一个就可以了    有一个就可以了    有一个就可以了
        //new PoiWordTools().refreshExcel(chart, listItemsByType, fldNameArr, titleArr);
        //刷新页面显示数据   数据中下标3开始的是折线图的数据，所以这个是3
        refreshLineStrGraphContent(lineChart, lineSerList, listItemsByType, fldNameArr, 2);
        
    }
    
    public static boolean refreshLineStrGraphContent(Object typeChart,
            List<?> serList, List<Map<String, String>> dataList, List<String> fldNameArr, int position) {
        
        boolean result = true;
        //更新数据区域
        for (int i = 0; i < serList.size(); i++) {
            CTAxDataSource cat = null;
            CTNumDataSource val = null;
            CTLineSer ser = ((CTLineChart) typeChart).getSerArray(i);
            
            cat = ser.getCat();
            // 获取图表的值
            val = ser.getVal();
            // strData.set
            
            CTNumData numData = val.getNumRef().getNumCache();
            
            numData.setPtArray((CTNumVal[]) null);
            
         
            long idx = 0;
            for (int j = 0; j < dataList.size(); j++) {
                //判断获取的值是否为空
                String value = "0";
                if (new BigDecimal(dataList.get(j).get(fldNameArr.get(i + position))) != null) {
                    value = new BigDecimal( dataList.get(j).get(fldNameArr.get(i + position))).toString();
                }
                if (!"0".equals(value)) {
                    CTNumVal numVal = numData.addNewPt();
                    numVal.setIdx(idx);
                    numVal.setV(value);
                }
                
            
                idx++;
            }
            numData.getPtCount().setVal(idx);
         
            
            
            //赋值横坐标数据区域
            String axisDataRange = new CellRangeAddress(1, dataList.size(), 0, 0)
                    .formatAsString("Sheet1", false);
            
            
            String numDataRange = new CellRangeAddress(1, dataList.size(), i + position, i + position)
                    .formatAsString("Sheet1", false);
            val.getNumRef().setF(numDataRange);
            
            
            
            
        }
        return result;
    }
    
    public static boolean refreshBarStrGraphContent(Object typeChart,
            List<?> serList, List<Map<String, String>> dataList, List<String> fldNameArr, int position) {
        boolean result = true;
        //更新数据区域
        for (int i = 0; i < serList.size(); i++) {
            CTAxDataSource cat = null;
            CTNumDataSource val = null;
            CTBarSer ser = ((CTBarChart) typeChart).getSerArray(i);
            
            // 设置标题 用以下这个方式，可以兼容office和wps
//            CTSerTx tx = ser.getTx();
//            tx.getStrRef().getStrCache().getPtList().get(0).setV("嘿嘿嘿");
            
            // Category Axis Data
            cat = ser.getCat();
            // 获取图表的值
            val = ser.getVal();
            // strData.set
            
            CTNumData numData = val.getNumRef().getNumCache();
            // unset old axis text
            numData.setPtArray((CTNumVal[]) null); // unset old values
            
            // set model
            long idx = 0;
            for (int j = 0; j < dataList.size(); j++) {
                //判断获取的值是否为空
                String value = "0";
                
                if (new BigDecimal(dataList.get(j).get(fldNameArr.get(i + position)).toString()) != null) {
                    value = new BigDecimal( dataList.get(j).get(fldNameArr.get(i + position)).toString()).toString();
                }
                if (!"0".equals(value)) {
                    CTNumVal numVal = numData.addNewPt();//序列值
                    numVal.setIdx(idx);
                    numVal.setV(value);
                }
                
                idx++;
            }
            numData.getPtCount().setVal(idx);
            
            
            
            //赋值横坐标数据区域
            String axisDataRange = new CellRangeAddress(1, dataList.size(), 0, 0)
                    .formatAsString("Sheet1", true);
           
            
            //数据区域
            String numDataRange = new CellRangeAddress(1, dataList.size(), i + position, i + position)
                    .formatAsString("Sheet1", true);
            val.getNumRef().setF(numDataRange);
            
            
        }
        return result;
    }
    
    public static boolean refreshExcel(XWPFChart chart,
            List<Map<String, String>> dataList, List<String> fldNameArr, List<String> titleArr) {
        boolean result = true;
        Workbook wb = new XSSFWorkbook();
        Sheet sheet = wb.createSheet("Sheet1");
        //根据数据创建excel第一行标题行
        for (int i = 0; i < titleArr.size(); i++) {
            if (sheet.getRow(0) == null) {
                sheet.createRow(0).createCell(i).setCellValue(titleArr.get(i) == null ? "" : titleArr.get(i));
            } else {
                sheet.getRow(0).createCell(i).setCellValue(titleArr.get(i) == null ? "" : titleArr.get(i));
            }
        }
        
        //遍历数据行
        for (int i = 0; i < dataList.size(); i++) {
            Map<String, String> baseFormMap = dataList.get(i);//数据行
            //fldNameArr字段属性
            for (int j = 0; j < fldNameArr.size(); j++) {
                if (sheet.getRow(i + 1) == null) {
                    if (j == 0) {
                        try {
                            sheet.createRow(i + 1).createCell(j).setCellValue(baseFormMap.get(fldNameArr.get(j)).toString() == null ? "" : baseFormMap.get(fldNameArr.get(j)).toString());
                        } catch (Exception e) {
                            if (baseFormMap.get(fldNameArr.get(j)) == null) {
                                sheet.createRow(i + 1).createCell(j).setCellValue("");
                            } else {
                                sheet.createRow(i + 1).createCell(j).setCellValue(baseFormMap.get(fldNameArr.get(j)).toString());
                            }
                        }
                    }
                } else {
                    String s = baseFormMap.get(fldNameArr.get(j));
                    BigDecimal b = new BigDecimal(s);
                    double value = 0d;
                    if (b != null) {
                        value = b.doubleValue();
                    }
                    if (value == 0) {
                        sheet.getRow(i + 1).createCell(j);
                    } else {
                        sheet.getRow(i + 1).createCell(j).setCellValue(b.doubleValue());
                    }
                }
            }
            
        }
        // 更新嵌入的workbook
        POIXMLDocumentPart xlsPart = chart.getRelations().get(0);
        OutputStream xlsOut = xlsPart.getPackagePart().getOutputStream();
        
        try {
            wb.write(xlsOut);
            xlsOut.close();
        } catch (IOException e) {
            e.printStackTrace();
            result = false;
        } finally {
            if (wb != null) {
                try {
                    wb.close();
                } catch (IOException e) {
                    e.printStackTrace();
                    result = false;
                }
            }
        }
        return result;
    }
    
    
    public static void replacePieCharts(POIXMLDocumentPart poixmlDocumentPart,
            List<String> titleArr, List<String> fldNameArr, List<Map<String, String>> listItemsByType) {
        XWPFChart chart = (XWPFChart) poixmlDocumentPart;
        chart.getCTChart();
        
        //根据属性第一列名称切换数据类型
        CTChart ctChart = chart.getCTChart();
        CTPlotArea plotArea = ctChart.getPlotArea();
        
        CTPieChart pieChart = plotArea.getPieChartArray(0);
        List<CTPieSer> pieSerList = pieChart.getSerList();  // 获取饼图单位
        
        //刷新内置excel数据
        refreshExcel(chart, listItemsByType, fldNameArr, titleArr);
        //刷新页面显示数据
        refreshPieStrGraphContent(pieChart, pieSerList, listItemsByType, fldNameArr, 1);
        
    }
    
    public static boolean refreshPieStrGraphContent(Object typeChart,
            List<?> serList, List<Map<String, String>> dataList, List<String> fldNameArr, int position) {
        
        boolean result = true;
        //更新数据区域
        for (int i = 0; i < serList.size(); i++) {
            //CTSerTx tx=null;
            CTAxDataSource cat = null;
            CTNumDataSource val = null;
            CTPieSer ser = ((CTPieChart) typeChart).getSerArray(i);
            
            //tx= ser.getTx();
            // Category Axis Data
            cat = ser.getCat();
            // 获取图表的值
            val = ser.getVal();
            // strData.set
            CTStrData strData = cat.getStrRef().getStrCache();
            CTNumData numData = val.getNumRef().getNumCache();
            strData.setPtArray((CTStrVal[]) null); // unset old axis text
            numData.setPtArray((CTNumVal[]) null); // unset old values
            
            // set model
            long idx = 0;
            for (int j = 0; j < dataList.size(); j++) {
                //判断获取的值是否为空
                String value = "0";
                if (new BigDecimal(dataList.get(j).get(fldNameArr.get(i + position))) != null) {
                    value = new BigDecimal(dataList.get(j).get(fldNameArr.get(i + position))).toString();
                }
                if (!"0".equals(value)) {
                    CTNumVal numVal = numData.addNewPt();//序列值
                    numVal.setIdx(idx);
                    numVal.setV(value);
                }
                CTStrVal sVal = strData.addNewPt();//序列名称
                sVal.setIdx(idx);
                sVal.setV(dataList.get(j).get(fldNameArr.get(0)));
                idx++;
            }
            numData.getPtCount().setVal(idx);
            strData.getPtCount().setVal(idx);
            
            
            //赋值横坐标数据区域
            String axisDataRange = new CellRangeAddress(1, dataList.size(), 0, 0)
                    .formatAsString("Sheet1", true);
            cat.getStrRef().setF(axisDataRange);
            
            //数据区域
            String numDataRange = new CellRangeAddress(1, dataList.size(), i + position, i + position)
                    .formatAsString("Sheet1", true);
            val.getNumRef().setF(numDataRange);
        }
        return result;
    }
}
